package com.danny.demo.single.signle_model;

/**
 * @ClassName: SingleObjectDCL
 * @Description: 双重校验锁/双检锁  (DCL，即 double-checked locking)  JDK1.5 起 这种方式采用双锁机制，安全且在多线程情况下能保持高性能
 * @Author: zhangdong
 * @Date: Created in 10:23 2019/6/26
 * @Version:
 */
public class SingleObjectDCL {
    private volatile static SingleObjectDCL singleObjectDCL;
    private SingleObjectDCL(){}

    public static SingleObjectDCL getSingleObjectDCL(){
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (singleObjectDCL==null){
            synchronized (SingleObjectDCL.class){
                if (singleObjectDCL == null){
                    singleObjectDCL = new SingleObjectDCL();
                }
            }
        }
        return singleObjectDCL;
    }
}
